﻿
function fdeptupdatebtn(){
	var update_dept_id=document.getElementById("update_dept_id").value;
	var update_dept_name=document.getElementById("update_dept_name").value;
	var headerdept_index=document.getElementById("update_dept_header").selectedIndex;
	var update_dept_header_value=document.getElementById("update_dept_header").options[headerdept_index].value;
	var statusdept_index=document.getElementById("update_dept_status").selectedIndex;
	var update_dept_status_value=document.getElementById("update_dept_status").options[statusdept_index].value;
	if(update_dept_id==""||update_dept_name==""||update_dept_header_value==""||update_dept_status_value==""){
		alert("抱歉。请将数据填写完才能更新！！！");
		return;
	}
	DeptCombine.updateDept(update_dept_id,update_dept_name,update_dept_header_value,update_dept_status_value,function(data) {
		if(data){
			alert("部门信息修改成功！");
			location.href="DeptManagerServlet";
		}else{
			alert("抱歉。部门信息修改失败！请检验你输入的信息！")
		}
	});
}
function fdeptnewbtn(){
	var new_dept_id=document.getElementById("new_dept_id").value;
	var new_dept_name=document.getElementById("new_dept_name").value;
	var headerdept_index=document.getElementById("new_dept_header").selectedIndex;
	var new_dept_header_value=document.getElementById("new_dept_header").options[headerdept_index].value;
	var statusdept_index=document.getElementById("new_dept_status").selectedIndex;
	var new_dept_status_value=document.getElementById("new_dept_status").options[statusdept_index].value;
	if(new_dept_id==""||new_dept_name==""||new_dept_header_value==""||new_dept_status_value==""){
		alert("抱歉。请将数据填写完才能新建！！！");
		return;
	}
	DeptCombine.addDept(new_dept_id,new_dept_name,new_dept_header_value,new_dept_status_value,function(data) {
		if(data){
			alert("部门新建成功！");
			location.href="DeptManagerServlet";
		}else{
			alert("抱歉。部门新建失败！请检验你输入的信息！")
		}
	});
}
function fdeptcombinebtn(){
	var combine_dept_id=document.getElementById("combine_dept_id").value;
	var combine_dept_name=document.getElementById("combine_dept_name").value;
	var dept_index=document.getElementById("depta").selectedIndex;
	var depta_value=document.getElementById("depta").options[dept_index].value;
	dept_index=document.getElementById("deptb").selectedIndex;
	var deptb_value=document.getElementById("deptb").options[dept_index].value;
	var headerdept_index=document.getElementById("combine_dept_header").selectedIndex;
	var combine_dept_header_value=document.getElementById("combine_dept_header").options[headerdept_index].value;
	var statusdept_index=document.getElementById("combine_dept_status").selectedIndex;
	var combine_dept_status_value=document.getElementById("combine_dept_status").options[statusdept_index].value;
	if(combine_dept_id==""||combine_dept_name==""||depta_value==""||deptb_value==""||combine_dept_header_value==""||combine_dept_status_value==""){
		alert("抱歉。请将数据填写完才能合并部门！！！");
		return;
	}
	DeptCombine.combineDept(combine_dept_id,combine_dept_name,depta_value,deptb_value,combine_dept_header_value,combine_dept_status_value,function(data) {
		if(data){
			alert("部门合并成功！");
			location.href="DeptManagerServlet";
		}else{
			alert("抱歉。部门合并失败！请检验你输入的信息！")
		}
	});
}
function fnewbtn(){
	var deptname=document.getElementsByName("deptname")[0].value;
	var headerdept=document.getElementsByName("headerdept")[0];
	var headerdept_index=headerdept.selectedIndex;
	var headerdept_value=headerdept.options[headerdept_index].value;
	if(deptname==""){
		alert("请填写部门名称！")
	}
}
function fnewdept(){
	var new_dept_header=document.getElementById("new_dept_header");
	DeptCombine.getAllDept(function(data) {
		DWRUtil.removeAllOptions(new_dept_header);
    	DWRUtil.addOptions(new_dept_header,{'':'请选择'});
		DWRUtil.addOptions(new_dept_header,data,'id','name');
	});
	document.getElementById("combine_div").style.display="none";
	document.getElementById("new_div").style.display="block";
	$("#pop_add_div").height(230);
}
function fcombinedept(){
	
	var dept_a=document.getElementById("depta");
	var dept_b=document.getElementById("deptb");
	var combine_dept_header=document.getElementById("combine_dept_header");
	DeptCombine.getAllDept(function(data) {
		DWRUtil.removeAllOptions(dept_a);
    	DWRUtil.addOptions(dept_a,{'':'请选择'});
		DWRUtil.addOptions(dept_a,data,'id','name');
		DWRUtil.removeAllOptions(dept_b);
    	DWRUtil.addOptions(dept_b,{'':'请选择'});
		DWRUtil.addOptions(dept_b,data,'id','name');
		DWRUtil.removeAllOptions(combine_dept_header);
    	DWRUtil.addOptions(combine_dept_header,{'':'请选择'});
		DWRUtil.addOptions(combine_dept_header,data,'id','name');
	});
	document.getElementById("new_div").style.display="none";
	document.getElementById("combine_div").style.display="block";
	$("#pop_add_div").height(300);
}

function changePageSize()
{
	var pageSize=$("#pageSize").val();
	location.href="DeptManagerServlet?pageSize="+pageSize;
}

/**
 * 按某值对一个select下拉框进行初始化
 */
function doInitSelectionstatus(update_dept_status, strValue)
{
	if (!update_dept_status || !strValue) return;

	for (var i = 0; i < update_dept_status.options.length; i++)
	{
		if (update_dept_status.options[i].value == strValue)
		{
			update_dept_status.selectedIndex = i;
			break;
		}
	}
}
function doInitSelectionheader(update_dept_header, strValue)
{
	if (!update_dept_header || !strValue) return;
	for (var i = 0; i < update_dept_header.options.length; i++)
	{
		if (update_dept_header.options[i].value == strValue)
		{
			update_dept_header.selectedIndex = i;
			break;
		}
	}
}